import requests

# 封装 tpshop 商城 接口对象层
class TpshopLoginApi(object):
    # 获取验证码
    @classmethod
    def get_verify(cls, session):
        session.get(url="http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=verify")

    # 登录
    @classmethod
    def login(cls, session, login_data):
        resp = session.post(url="http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=do_login",
                            data=login_data)
        return resp


# 测试，自己封装的接口，功能是否正常！
if __name__ == '__main__':
    session = requests.Session()
    # 发送获取验证码请求
    TpshopLoginApi.get_verify(session)

    login_data = {"username": "15727597562", "password": "HZCwasd123", "verify_code": "8888"}
    # 发送登录请求
    response = TpshopLoginApi.login(session, login_data)

    print("登录结果：", response.json())